<template>
    <el-row class="container">
        <el-col :span="24" class="header" v-bind:class="color">
            <el-col :span="3" style="font-size: 20px;text-align: center">
                {{sysName}}
            </el-col>
            <el-col :span="1">
                <div class="tools" @click.prevent="collapse">
                    <i class="el-icon-s-grid"></i>
                </div>
            </el-col>
            <el-col :span="16">
                <div class="block" style="float: right; margin-top: 10px">
                    <el-color-picker v-model="color"></el-color-picker>
                </div>
            </el-col>

            <el-col :span="4" class="userinfo">
                <el-dropdown trigger="hover">
                    <span class="el-dropdown-link userinfo-inner"><img
                            :src="this.sysUserAvatar"/>刘牌</span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item>我的消息</el-dropdown-item>
                        <el-dropdown-item>设置</el-dropdown-item>
                        <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-col>
        </el-col>
        <el-col :span="24" class="main">
            <aside :class="collapsed?'menu-collapsed':'menu-expanded'">
                <el-menu :default-active="routes.path"
                         class="el-menu-vertical-demo"
                         :unique-opened="true"
                         router
                         v-show="!collapsed"
                         style="width: 210px"
                         background-color="#303133"
                         text-color="#FFFFFF"
                >
                    <SideTree v-for="item in routes" :key="item.id" :menu="item"></SideTree>
                </el-menu>
                <!--导航菜单-折叠后-->
                <ul class="el-menu el-menu-vertical-demo collapsed" v-show="collapsed" ref="menuCollapsed"
                    style="background-color: #333744">
                    <li v-for="(item,index) in routes" class="el-submenu item">
                        <template>
                            <div class="el-submenu__title" style="padding-left: 20px;" @mouseover="showMenu(index,true)"
                                 @mouseout="showMenu(index,false)"><i :class="item.menuIcon"></i></div>
                            <ul class="el-menu submenu" :class="'submenu-hook-'+index" @mouseover="showMenu(index,true)"
                                @mouseout="showMenu(index,false)">
                                <li v-for="child in item.children" :key="child.menuUrl"
                                    class="el-menu-item"
                                    style="padding-left: 40px;background-color: #333744;color: white"
                                    :class="item.menuUrl==child.menuUrl?'is-active':''"
                                    @click="this.$router.push(child.menuUrl)">{{child.menuName}}
                                </li>
                            </ul>
                        </template>
                    </li>
                </ul>
            </aside>

            <section class="content-container">
                <div class="grid-content bg-purple-light" style="text-align: left;">
                    <el-main style="margin-top: -20px">
                        <el-breadcrumb separator=">>" class="breadcrumb-inner">
                            <el-breadcrumb-item :to="{ path: '/Welcome' }">
                                <span><icon class="el-icon-s-home">首页</icon></span>
                            </el-breadcrumb-item>
                            <el-breadcrumb-item v-for="item in $route.matched" :key="item.path"
                                                style="text-align: left;">
                                {{ item.name }}
                            </el-breadcrumb-item>
                        </el-breadcrumb>
                        <div style="margin-top: 20px">
                            <el-card class="box-card">
                                <router-view/>
                            </el-card>
                        </div>
                    </el-main>
                </div>
            </section>
        </el-col>
    </el-row>
</template>

<script>
    import {removeToken} from "../utils/token";
    import SideTree from "../components/Tree/SideTree";
    export default {
        components: {
            SideTree
        },

        data() {
            return {
                color:'#409EFF',
                sysName: '人间草木管理系统',
                collapsed: false,
                sysUserName: 'steak',
                sysUserAvatar: require('../assets/吉他.jpg'),
                routes: [], //路由
                location: '',
                collShowOpen:true,
                collShowDown:false
            }
        },

        created() {
            //路由
            const route = this.$store.getters.routes;

            this.routes = route;
            this.location = sessionStorage.getItem("city");
        },

        methods: {
            //退出登录
            logout() {
                var _this = this;
                this.$confirm('确认退出吗?', '提示', {
                    //type: 'warning'
                }).then(() => {
                    removeToken('tokenKey')
                    _this.$router.push('/login');
                }).catch(() => {

                });


            },
            //折叠导航栏
            collapse: function () {
                this.collapsed = !this.collapsed;
            },
            showMenu(i, status) {
                this.$refs.menuCollapsed.getElementsByClassName('submenu-hook-' + i)[0].style.display = status ? 'block' : 'none';
            },
        },
    }


</script>

<style scoped lang="scss">
    a {
        text-decoration: none;
    }

    .container {
        position: absolute;
        top: 0px;
        bottom: 0px;
        width: 100%;

        .header {
            height: 60px;
            background-color: lightslategray;
            line-height: 60px;
            color: #fff;

            .userinfo {
                text-align: right;
                padding-right: 35px;
                float: right;

                .userinfo-inner {
                    cursor: pointer;
                    color: #fff;

                    img {
                        width: 40px;
                        height: 40px;
                        border-radius: 20px;
                        margin: 10px 0px 10px 10px;
                        float: right;
                    }
                }
            }

            .logo {
                //width:230px;
                height: 60px;
                font-size: 12px;
                padding-left: 20px;
                padding-right: 20px;
                border-color: rgba(238, 241, 146, 0.3);
                border-right-width: 1px;
                border-right-style: solid;

                img {
                    width: 40px;
                    float: left;
                    margin: 10px 10px 10px 18px;
                }

                .txt {
                    color: #fff;
                }
            }

            .logo-width {
                width: 240px;
            }

            .logo-collapse-width {
                width: 60px
            }

            .tools {
                padding: 0px 23px;
                width: 14px;
                height: 60px;
                line-height: 60px;
                cursor: pointer;
            }
        }

        .main {
            display: flex;
            position: absolute;
            top: 60px;
            bottom: 0px;
            overflow: hidden;
            margin-top: 0px;

            aside {
                flex: 0 0 230px;
                width: 230px;

                .el-menu {
                    height: 100%;
                }

                .collapsed {
                    width: 60px;

                    .item {
                        position: relative;
                    }

                    .submenu {
                        position: absolute;
                        top: 0px;
                        left: 60px;
                        z-index: 99999;
                        height: auto;
                        display: none;
                    }

                }
            }

            .menu-collapsed {
                flex: 0 0 60px;
                width: 60px;
            }

            .menu-expanded {
                flex: 0 0 230px;
                width: 230px;
            }

            .content-container {
                background-color: #fff;
                flex: 1;
                overflow-y: scroll;
                padding: 20px;

                .breadcrumb-container {
                    .title {
                        width: 200px;
                        float: left;
                        color: #475669;
                    }

                    .breadcrumb-inner {
                        float: right;
                    }
                }

                .content-wrapper {

                    box-sizing: border-box;
                }
            }

        }

        .item1 {
            font-size: 14px;
            margin-left: -700px;
        }

        .item2 {
            font-size: 14px;
            margin-left: 40px;
        }

        .item3 {
            font-size: 14px;

            margin-left: 40px;
        }

        .item4 {
            font-size: 14px;
            margin-left: 40px;
        }

        .item5 {
            font-size: 14px;
            margin-left: 35px;
        }

        .item6 {
            font-size: 14px;
            margin-left: 50px;
            margin-left: 50px;
        }

        .icon {
            width: 25px;
            margin-top: 10px;
            margin-left: -45px;
            margin-bottom: 20px;
        }
    }
</style>
